<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div>
	<form id="infoForm" target="hiddenFrame" action="${path}/mc/usersaveInfo" method="post">
		<fieldset style="padding-left: 10px;">
		  	<input type="hidden" name="entity.id" value="${entity.id}" />
		  	<input type="hidden" id="hidRoleIdStr" name="roleIdStr" value="${roleIdStr}" />
		  	<input type="hidden" id="hidIsAdmin" value="${entity.isAdmin}" />
			<table>
			  	<tr>
			  		<td>帐号</td>
			  		<td>
			  			<input type="text" autocomplete="off" name="entity.account" value="${entity.account}" class="{required:true,messages:{required:'请输入帐号'}}" />
			  		</td>
			  	</tr>
			  	<tr>
			  		<td>性别</td>
			  		<td>
			  			<select name="entity.sex" dir="${entity.sex}" >
			  				<option value="1">男</option>
			  				<option value="2">女</option>
			  			</select>
			  		</td>
			  	</tr>
			  	<tr>   <!--style="display:none;"-->
			  		<td>超级管理员</td>
			  		<td type="hidden">
			  			<select display=none id="selIsAdmin" name="entity.isAdmin" dir="${entity.isAdmin}">
			  				<option value="1">是</option>
			  				<option value="2" selected="selected">否</option>
			  			</select>
			  		</td>
			  	 </tr>
			  	<%-- <c:if test="${empty entity.id}"> --%>
			  		<tr>
				  		<td>密码</td>
				  		<td>
				  			<input id="txtPwd" autocomplete="off" type="password" name="entity.password" " class="{required:true,messages:{required:'请输入密码'}}" />
				  		</td>
				  	</tr>
				  	<tr>
				  		<td>确认密码</td>
				  		<td>
				  			<input type="password" class="{required:true, equalTo:'#txtPwd', messages:{required:'请确认密码', equalTo:'密码不一致'}}" />
				  		</td>
				  	</tr>
			  	<%-- </c:if> --%>
			 	
			  <!-- <tr type="hidden">
			  		<td type="hidden" id="selIsAdmin" name="entity.isAdmin" value=1></td>
			  </tr> -->
		   </table>
		</fieldset>
	</form>
</div>
<div>
	<c:import url="/mc/permission/role/search.jsp" />
	<table id="tblDetailRole"></table>
</div>
<script type="text/javascript">
	$(function(){
		$("#selIsAdmin").change(function(){
			//选择超级管理员，隐藏角色选择，设置隐藏域的值，用于控制flexigrid显隐
			if($(this).val() === "1") {
				$(".flexigrid").hide();
				$("#hidIsAdmin").val("1");
			} else {
				$(".flexigrid").show();
				$("#hidIsAdmin").val("2");
			}
		});
		
		$(".detail #infoForm").submit(function(){
			var adminStatus = $("#selIsAdmin").val();
			if(adminStatus == 2) {
				var detailDiv = $(this).parents(".detail");
				var ids = [];
				var cbxChoosedRole = $("#tblDetailRole :checkbox:checked", detailDiv);
				if(cbxChoosedRole.length === 0) {
					hiAlert("请选择角色！", "提示");
					return false;
				}
				//保存选中的角色id
				cbxChoosedRole.each(function(){
					ids.push($(this).val());
				});
				//拼接角色id并设置
				var choosedRoleMixStr = ids.join(",");
				$("#hidRoleIdStr", this).val(choosedRoleMixStr);
			}
			return true;
		});
	});
</script>